<!--
 * @Descripttion: appid管理（测试环境）
 * @version: 
 * @Author: zhangfan
 * @email: 2207044692@qq.com
 * @Date: 2021-04-12 15:27:34
 * @LastEditors: zhangfan
 * @LastEditTime: 2021-04-28 16:57:17
-->
<template>
  <div class="container" ref="mainCon">
    <!-- <topTitle :titleText="titleText" :btnText="btnText" :isShowBtn="isShowBtn"></topTitle> -->
    <div
      class="reminderTop"
      v-if="topTipShow"
      :style="{ margin: topTipShow ? '0' : '24px 24px 0 24px' }"
    >
      <i class="el-icon-warning"></i>应用类型维护说明：您所使用的【
      <span style="color: #ff4242"
        >{{ inputInfo.serverName }}{{ inputInfo.version }}</span
      >】版本维护，暂时无法与平台对接，如有问题请与管理员联系。
    </div>
    <div class="titleBoxTop">
      <div class="titleBox">
        <span class="blockTitle">appId及接口管理</span>
        <el-tag
          type="success"
          class="tag-item"
          style="background: #409eff; border-color: #409eff; color: #fff"
          >{{ departmentTypeFun }}</el-tag
        >
      </div>
    </div>
    <div class="mainCon" :style="{ top: topTipShow ? '104px' : '68px' }">
      <el-row class="searchBox searchInputWidth">
        <el-form :inline="true" :model="filterField" ref="accountForm">
          <el-col :lg="8" :xl="6">
            <el-form-item label="appId" class="row-padding-bottom">
              <el-input
                placeholder="请输入"
                clearable
                v-model="filterField.appId"
                @blur="filterField.appId = changeValue($event)"
              />
            </el-form-item>
          </el-col>
          <el-col :lg="8" :xl="6">
            <el-form-item label="状态" class="row-padding-bottom">
              <el-select
                placeholder="请选择"
                v-model="filterField.enabled"
                clearable
              >
                <el-option label="启用" value="ENABLED" />
                <el-option label="停用" value="DISABLE" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-form-item>
            <el-button
              type="primary"
              icon="icon iconfont iconchazhao1"
              @click="searchTable"
              class="searchBtn"
            >
              <span>搜索</span>
            </el-button>
          </el-form-item>
        </el-form>
      </el-row>
      <div class="spacing"></div>
      <!-- 列表 -->
      <div
        ref="tableBox"
        :class="hiddleToolBar ? 'tableBoxCur tableBox' : 'tableBoxCur'"
      >
        <el-table
          ref="tableBox1"
          :max-height="tableHeight"
          :data="tableData"
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
          highlight-current-row
          stripe
          v-loading="loading"
          style="border: 1px solid #dfe6ec"
        >
          <el-table-column
            align="center"
            prop="appId"
            label="appID"
            :formatter="formatTd"
            min-width="280px"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="appSecret"
            label="appSecret"
            :formatter="formatTd"
            min-width="280px"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="effectiveEndDate"
            label="有效期"
          >
            <template slot-scope="scope">
              <p
                v-if="
                  scope.row.effectiveEndDate == '4712-12-31' ||
                  scope.row.effectiveEndDate == '4712-12-31 00:00:00'
                "
              >
                长期有效
              </p>
              <p
                v-else-if="currentTime > scope.row.effectiveEndDate"
                style="color: #ff4242"
              >
                {{ scope.row.effectiveEndDate }} (已过期)
              </p>
              <p v-else>{{ scope.row.effectiveEndDate }}</p>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="enabledName"
            label="状态"
            filter-placement="bottom-end"
          >
            <template slot-scope="scope">
              <!-- 1.当由于技术后台禁用该appId时，气泡窗展示“该appId已被管理员设为禁用，如有问题请与管理员联系”
                        2.当appId过期时，气泡窗展示“该appId已过有效期，如有问题请与管理员联系”客户端暂时影藏 -->
              <!-- <el-button
              v-if="scope.row.enabled === 'ENABLED'"
              size="mini"
              type="success"
              disable-transitions
              >{{ scope.row.enabledName }}</el-button
            >
            <el-tooltip
              v-else
              class="item"
              effect="dark"
              :content="
                scope.row.enabled === 'DISABLE' &&
                currentTime > scope.row.effectiveEndDate
                  ? '该appId已过有效期，如有问题请与管理员联系'
                  : '该appId已被管理员设为禁用，如有问题请与管理员联系'
              "
              placement="top"
            >
              <el-button size="mini" type="danger" disable-transitions>{{
                scope.row.enabledName
              }}</el-button> -->
              <el-button
                size="mini"
                :type="scope.row.enabled === 'ENABLED' ? 'success' : 'danger'"
                disable-transitions
                >{{ scope.row.enabledName }}</el-button
              >
              <!-- </el-tooltip> -->
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="操作"
            width="250px"
            fixed="right"
          >
            <template slot-scope="scope">
              <div>
                <el-link
                  v-if="isShowUpdate"
                  type="primary"
                  @click="toDetail(scope.row)"
                  >查看详情</el-link
                >
                <el-link
                  v-if="
                    (scope.row.inputTypeName == '政府部门' && isShowUpdate) ||
                    (scope.row.inputTypeName == '第三方平台' && isShowUpdate)
                  "
                  type="primary"
                  @click="designatedItem(scope.row)"
                  >查看项目</el-link
                >
                <el-link
                  v-if="isShowUpdate"
                  type="primary"
                  @click="dockingLog(scope.row)"
                  >对接日志</el-link
                >
              </div>
            </template>
          </el-table-column>
          <!-- 表格数据为空时，页面显示 -->
          <div slot="empty" v-show="isShow">
            <emptyTable emptyText="暂无相关信息" />
          </div>
        </el-table>
        <!-- filterField为搜索条件 -->
        <Pagination
          ref="pagination"
          @getList="getTableList"
          :filterField="filterField"
          :requestUrl="requestUrl"
          @getpageSize="getpageSize"
          @getpageNo="getpageNo"
        />
      </div>
    </div>
  </div>
</template>

<script>
import common from '../../kits/common'
import scrollTable from '@/mixin/scrollTable.js'

export default {
  name: 'equipmentAppidCs',
  mixins: [scrollTable],
  data() {
    return {
      topTipShow: false, //enabled 启用显示  DISABLE 禁用不显示顶部
      inputInfo: {},
      requestUrl: 'api-m/inputUserAuth/base/v1/page', //表格请求路径
      loading: false,
      departmentTypeFun: '测试环境',
      isShow: false,
      tableData: [], //表格数据
      tableData: [], //表格数据
      filterField: {
        appId: '',
        enabled: '',
        userId: '',
      },
      pageSize: 20,
      pageNo: 1,
      currentTime: '', //当前时间
      isShowAdd: '',
      isShowUpdate: '',
    }
  },
  created() {
    //获取当前时间
    this.getCurrentTime()
    this.filterField.userId = this.$store.state.userId
    //获取环境，名称，版本号
    this.getInputUserServer()
    this.$nextTick(function () {
      this.$refs.pagination.getTableListData()
    })
    this.isShowAdd =
      this.$store.state.buttonLimitsArr.indexOf('prodAppIdManage:add') > -1
    this.isShowUpdate =
      this.$store.state.buttonLimitsArr.indexOf('prodAppIdManage:update') > -1
  },
  methods: {
    getInputUserServer() {
      this.axios({
        method: 'post',
        url: 'api-m/inputUserServer/base/v1/list',
        data: {
          userId: this.$store.state.userId,
        },
      })
        .then((response) => {
          if (!response.data.hasError) {
            this.inputInfo = response.data.result[0] || {}
            //enabled 启用显示  DISABLE 禁用不显示顶部
            this.topTipShow = this.inputInfo.enabled == 'ENABLED' ? false : true
          } else {
            this.$message({
              type: 'error',
              message: response.data.errorMsg,
            })
          }
        })
        .catch((error) => {
          this.$message.error('数据获取失败')
        })
    },
    getCurrentTime() {
      var now = new Date()
      var year = now.getFullYear()
      var month = now.getMonth() + 1
      var day = now.getDate()
      var time = year + '-' + common.pad(month) + '-' + common.pad(day)
      this.currentTime = time
    },
    getpageSize(val) {
      this.pageSize = val
    },
    getpageNo(val) {
      this.pageNo = val
    },
    getTableList(data) {
      this.tableData = data
      this.loading = false
      if (this.tableData.length < 1) {
        this.isShow = true
      }
    },
    //列表查询
    searchTable() {
      this.$refs.pagination.getTableListData()
    },
    //查看详情
    toDetail(row) {
      this.$router.push({
        path: '/home/interfacePlatform/equipmentAppidDetail',
        name: 'equipmentAppidDetail',
        query: {
          type: 'cs',
          id: row.id, //列表主键id
          userId: row.userId, //用户id
          appId: row.appId,
        },
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/interfacePlatform/equipmentAppidCs',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
    //查看项目
    designatedItem(row) {
      this.$router.push({
        path: '/home/interfacePlatform/designatedItem',
        name: 'designatedItem',
        query: {
          type: 'cs',
          id: row.id, //列表主键id
          userId: row.userId, //用户id
        },
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/interfacePlatform/equipmentAppidCs',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
    //对接日志
    dockingLog(row) {
      this.$router.push({
        path: '/home/interfacePlatform/dockingLog',
        name: 'dockingLog',
        query: {
          appId: row.appId,
          type: 'cs',
        },
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/interfacePlatform/equipmentAppidCs',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
  },
}
</script>

<style scoped lang="less">
.container {
  .reminderTop {
    color: #666;
    font-size: 14px;
    background: #fffbe6;
    line-height: 36px;
    border-radius: 3px;
    padding: 0 24px;
    margin: 24px 24px 0 24px;
    i {
      color: #ffaa00;
      margin-right: 4px;
      font-size: 20px;
      vertical-align: -2px;
    }
  }
  .selectWidth {
    width: 100%;
  }
  .titleBoxTop {
    height: 56px;
    line-height: 56px;
    background-color: #fff;
    padding: 0 24px;
  }
  .titleBox {
    height: 56px;
    line-height: 56px;
    padding: 0;
    border-bottom: 1px solid #e3e7e9;
    margin-bottom: 0px;
    .blockTitle {
      font-weight: bold;
      font-size: 18px;
      color: #333;
      line-height: 24px;
    }
  }
}
/deep/ .el-tag {
  line-height: 23px;
  height: 23px;
}
@import '../../../static/css/filterArea.less';
</style>
